<?php
class DBMResultSet implements Iterator, ArrayAccess {
	private $resultCount;
	private $results;
	private $offset;
	private $fields;
	
	public function __construct(){
		$this->resultCount = 0;
		$this->results = array();
		$this->offset = 0;
	}
	
	public function getFields(){
		return $this->fields; 
	}
	
	public function setFields(array $fields){
		$this->fields = $fields;
	}
	
	public function getResultCount(){
		return $this->resultCount;
	}
	
	function rewind() {
        $this->offset = 0;
    }

    function current() {
        return $this->offsetGet($this->offset);
    }

    function key() {
        return $this->offset;
    }

    function next() {
        ++$this->offset;
    }

    function valid() {
        return $this->offsetExists($this->offset);
    }
	
	public function offsetSet($offset, $value) {
		if(is_null($offset)){
			$offset = $this->resultCount;
		}
		if(!is_int($offset)){
			throw new Exception("DBMResultSet supports only integer as offsets!");
		}
        $this->results[$offset] = $value;
        $this->resultCount++;
    }
    
    public function offsetExists($offset) {
        return isset($this->results[$offset]);
    }
    
    public function offsetUnset($offset) {
        unset($this->results[$offset]);
    }
    
    public function offsetGet($offset) {
        return isset($this->results[$offset]) ? $this->results[$offset] : null;
    }
}
?>